package km.TestSMS;

import java.util.*;

import android.app.*;
import android.content.*;
import android.net.*;
import android.os.Bundle;
import android.telephony.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;

public class TestSMS extends Activity {
	private Button btn_sms;
	private Button btn_call;
	private Button btn_sms_d;
	private Button btn_call_d;
	private Button btn_add_con;
	private Button btn_mms;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn_sms = (Button)findViewById(R.id.Button01);
        btn_call = (Button)findViewById(R.id.Button02);
        btn_sms_d = (Button)findViewById(R.id.Button03);
        btn_call_d = (Button)findViewById(R.id.Button04);
        btn_add_con = (Button)findViewById(R.id.Button05);
        btn_mms = (Button)findViewById(R.id.Button07);
        btn_sms.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				sendSMSIntent("01045839998","hello~!! \n aaa111111111122222222222223333333333333444444444444411111111112222222222222333333333333344444444444441111111111222222222222233333333333334444444444444\nggggggggggggggggg");
			}
		});
        btn_sms_d.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				sendSMSManager("01045839998","hello~!! \n aaa");
			}
		});
        btn_mms.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		sendMMS("01045839998","hello~!!aaaa1111111111222222222222233333333333334444444444444111111111122222222222223333333333333444444444444411111111112222222222222333333333333344444444444441111111111222222222222233333333333334444444444444lllll");
        		//01023912237
        	}
        });
        btn_call.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		callDialIntent("01045839998");
        	}
        });
        btn_call_d.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		callDialManager("01045839998");
        	}
        });
        btn_add_con.setOnClickListener(new OnClickListener() {
        	public void onClick(View v) {
        		addContact("01045839998");
        	}
        });
    }
    private void sendSMSManager(String toNum, String toMsg){
	       PendingIntent pi = PendingIntent.getActivity(TestSMS.this, 0,
	               new Intent(TestSMS.this,TestSMS.class), 0);	      
	           SmsManager sms = SmsManager.getDefault();	  
	           try{	        	   
	           sms.sendTextMessage(toNum, null, toMsg, pi, null);
//	           sms.sendMultipartTextMessage(toNum, null, sms.divideMessage("111111111112222222222222333333333333344444444444445555555555566666666666")
//	        		   , pi, null);
	           }catch (Exception e) {
	        	   	e.printStackTrace();
			}
    }
    private void sendMMS(String toNum, String toMsg){
    	
        SmsManager sms = SmsManager.getDefault();
        try { 
        	ArrayList<PendingIntent> listOfIntents = new ArrayList<PendingIntent>(); 
        	//PendingIntent il = PendingIntent.getBroadcast(this, 0, new Intent(),0); 
        	ArrayList<String> messages = sms.divideMessage(toMsg); 
        	Log.v("****************", messages.toString()); 
        	for (int i=0; i < messages.size(); i++){ 
        	PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(),0); 
        	listOfIntents.add(pi); 
        	} 
        	sms.sendMultipartTextMessage(toNum, null, messages, 
        	listOfIntents, null); 
        	} catch (Exception e) { Log.i("TEST", e.toString()); 
        	}
    }
    private void sendSMSIntent(String toNum, String toMsg){

	    Uri uri = Uri.parse ("smsto:"+toNum); 
	    Intent sendIntent = new Intent (Intent.ACTION_SENDTO, uri);
	    sendIntent.putExtra("sms_body", toMsg);
	    startActivity(sendIntent);
	    
//	    Uri mmsUri = Uri.parse("content://media/external/images/media/1");   
//	    Intent intent = new Intent(Intent.ACTION_SEND);
//	    intent.putExtra("sms_body", "Hi how are you");  
//	    intent.putExtra(Intent.EXTRA_STREAM, mmsUri);   
//	    intent.setType("image/png");   
//	    startActivity(intent); 
    }
    
    
    private void callDialIntent(String toNum){
    Uri uri = Uri.parse("tel:"+toNum);
    Intent it = new Intent(Intent.ACTION_DIAL, uri);  
    startActivity(it);  
    }
    private void callDialManager(String toNum){
        Uri uri = Uri.parse("tel:"+toNum);
        Intent it = new Intent(Intent.ACTION_CALL, uri);  
        startActivity(it); 
 }
    private void addContact(String toNum){
    	Uri uri = Uri.parse("tel:"+toNum);
    	Intent it = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    	it.setType("vnd.android.cursor.item/person");
    	it.putExtra("tel", toNum);
    	startActivity(it); 
//act=android.intent.action.INSERT_OR_EDIT typ=vnd.android.cursor.item/person cmp=com.android.contacts/com.samsung.android.contacts.ui.InsertOrNewActivity (has extras) }    	
    }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	Log.e("", "onActivityResult >>"+resultCode);
	
	super.onActivityResult(requestCode, resultCode, data);
}
}